<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/10/7 Time: 15:30
 */

namespace App\Http\Controllers\Admin\System;


use App\Http\Controllers\Controller;
use App\Http\Request\System\ConfigStore;
use App\Repositories\System\ConfigRepository;
use Illuminate\Http\Request;


class ConfigController extends Controller
{
    private $config;

    public function __construct(ConfigRepository $config)
    {
        $this->config = $config;
    }

    public function index()
    {
        return $this->config->configs();
    }


    /**
     *
     * show
     * @author Paco
     * @createTime 2018/10/7 16:01
     * @param ConfigStore $config
     * @param Request $request
     * @return array|mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function show(ConfigStore $config, Request $request)
    {
        $params = $config->validated($request);
        $prefix = $request->input('prefix', '');
        return $this->config->config($params['name'], $prefix);
    }

    /**
     *
     * update
     * @author Paco
     * @createTime 2018/10/7 16:05
     * @param ConfigStore $config
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    function save(ConfigStore $config, Request $request)
    {
        $params = $config->validated($request);
        return $this->config->saveConfig($params['config_id'], $params);
    }

    /**
     *
     * addConfig
     * @author Paco
     * @createTime 2018/10/7 16:05
     * @param ConfigStore $config
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    function store(ConfigStore $config, Request $request)
    {
        $params = $config->validated($request);
        return $this->config->addConfig($params);
    }
}